package com.zwan.oam_rtc.utils.messages;

import java.nio.ByteBuffer;

/***
 * PID包含
 * pno unit module postoffice 
 * 
 * @author 
 *
 */
public class PID extends AbstractStruct {

	public static final int MSG_LENGTH = 5; 
	
	private int pno = 0;
	private short unit = 0;
	private short module = 0;
	private short postoffice = 0;
	
	public PID(){
		
	}

	public PID(int pno, short unit, short module, short postoffice) {
		this.pno = pno;
		this.unit = unit;
		this.module = module;
		this.postoffice = postoffice;
	}

	public short getModule() {
		return module;
	}

	public void setModule(short module) {
		this.module = module;
	}

	public int getPno() {
		return pno;
	}

	public void setPno(int pno) {
		this.pno = pno;
	}

	public short getPostoffice() {
		return postoffice;
	}

	public void setPostoffice(short postoffice) {
		this.postoffice = postoffice;
	}

	public short getUnit() {
		return unit;
	}

	public void setUnit(short unit) {
		this.unit = unit;
	}

	public int getLength() {
		return MSG_LENGTH;
	}

	/**
	 * 从buffer读出PID，10bytes
	 */
	public void readFromBuffer(ByteBuffer bf) {
		pno = bf.getShort();  //当前位置按当前order读取两个字节数据转换为short，指针增加2
		if (pno < 0)
			pno += 65536;
		unit = (short)bf.get();//读取一个字节
		if (unit < 0)
			unit += 256;
		module = (short)bf.get();
		if (module < 0)
			module += 256;
		postoffice = (short)bf.get();
		if (postoffice < 0)
			postoffice += 256;
	}
	/**
	 * 将PID写入buffer，10bytes
	 */
	public void writeToBuffer(ByteBuffer bf) {
		bf.putShort((short)pno);
		bf.put((byte)unit);
		bf.put((byte)module);
		bf.put((byte)postoffice);
	}
}
